//
//  CommonEvaluateCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/12.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "CommonEvaluateCell.h"

@implementation CommonEvaluateCell

+ (CGFloat)calculateHeightWithModel:(CommunityEvaModel *)model {

    CGFloat height = 50 + [Utilities getStringHeightWithText:model.content font:[UIFont systemFontOfSize:14] viewWidth:(TTScreenWidth - 108)] + 10;
    return height;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.userIcon pp_clipCorners:UIRectCornerAllCorners radius:self.userIcon.frame.size.height/2];
    });
}

- (void)fillWithModel:(CommunityEvaModel *)model {
    
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:model.replyUserHeadUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.userName.text = model.replyUserNickName;
    self.timeLab.text = model.createTime;
    self.contentLab.text = model.content;
    
    [self.thumbBtn setTitle:[NSString stringWithFormat:@" %ld",model.likes] forState:UIControlStateNormal];

    if (model.isZan.length > 0) {
        [self.thumbBtn setImage:[UIImage imageNamed:@"tanhun_zan_sel"] forState:UIControlStateNormal];
        [self.thumbBtn setTitleColor:UIColorHex(0xFF4242) forState:UIControlStateNormal];
    } else {
        [self.thumbBtn setImage:[UIImage imageNamed:@"tanhun_zan"] forState:UIControlStateNormal];
        [self.thumbBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    }

}


- (IBAction)thumbAction:(id)sender {
    if (self.CommonEvaluateCellBlock) {
        self.CommonEvaluateCellBlock(CommunityActionType_Thumb);
    }
}


@end
